//
//  FocusMeCell.m
//  唧歪
//
//  Created by ZC on 15/9/2.
//  Copyright (c) 2015年 MWJ. All rights reserved.
//

#import "FocusMeCell.h"
#import "AppDelegate.h"

#define shieldURL @"https://app.jiwaipro.com:8888/index.php/JiWai/shield"

@implementation FocusMeCell{
    NSString *shieldStr;
    AppDelegate *app;
    NSMutableArray *shieldArray;
}

- (void)awakeFromNib {
    // Initialization code
    shieldArray = [NSMutableArray array];
    app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [self.shielding addTarget:self action:@selector(switchclick) forControlEvents:UIControlEventValueChanged];
}
-(void)switchclick{
    if ([self.shielding isOn]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"您已取消屏蔽此用户" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        shieldStr = @"0";
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"您已屏蔽此用户" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        shieldStr = @"1";
    }
    NSString *string = [NSString stringWithFormat:@"myuser_id=%@&heuser_id=%@&focus_shield=%@",app.user_id,self.focus_ID,shieldStr];
    [self shieldPath:shieldURL Str:string];
}
-(void)shieldPath:(NSString *)path Str:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        shieldArray =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        [self performSelectorOnMainThread:@selector(shieldData) withObject:shieldArray waitUntilDone:YES];
    }];
}
-(void)shieldData{
    NSLog(@"成功");
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
